package com.eregg.learn.netty.demo.pipeline.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

public class ServerOutHandlerA extends ChannelOutboundHandlerAdapter {
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        System.out.println("ServerOutHandlerA");
        ByteBuf buffer = (ByteBuf) msg;
        buffer.writeBytes(" -> outboundA".getBytes());

        byte [] bytes = new byte[buffer.writerIndex()];
        buffer.readBytes(bytes);
        System.out.println(new String(bytes));
        super.write(ctx, buffer, promise);
    }
}
